package NG::Gen::Task::StatUp;
use strict;
use warnings;
use utf8;

use NG::Sys::App;

use NG::Sys::Datetime;
our @ISA = qw(NG::Gen::Task::Task);

sub delay {
	my $self = shift;
	my $stat_name = $self->param()->{stat};
	my $main_unit = $self->param()->{unit};
	my $level = $self->{user}->stat->$stat_name() + 1;
	my $ul = $self->{leader}->units->get_by_key($main_unit,1);
	my $count = 1 + (@$ul && $ul->[0]->count);

	my $bt = $self->param()->{b_time};
	my $kl = $self->param()->{k_level};
	my $kc = $self->param()->{k_count};
	
	my $delay = int($bt * ($level * $kl) / ($count * $kc));

	return $delay;
}
sub make_context {
	my $self = shift;
	my $sm = $self->param()->{stat};
	my $cur = $self->{user}->stat->$sm() || 0;
	return {
		from => $cur,
		to => $cur + 1,
	};
}

sub before_assign {
	my $self = shift;
	unless($self->check_condition){
		return "Не выполняются условия";
	}
	return 0;
}
sub before_done {
	my $self = shift;
	my $sm = $self->param()->{stat};
	my $cur = $self->{user}->stat->$sm() || 0;
	$self->{user}->stat->$sm($cur + 1);
	return 0;
}

1;
